﻿@using Shop.Entity;
@using Shop.Help;
@using Shop.Bll;
@using System.Data;
@using Shop.Help;
@using Webdiyer.WebControls.Mvc;
@{
    Layout = null;
    string serverPath = Safe.GetWebConfigValueByKey("ServerPath");
    string actionString = RoleLogic.GetPowerStr("BusinessCoupon", ManagerLogic.GetLoginInfo().ManagerRoleGuid);
}
@model  PagedList<DataRow>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>列表</title>
    <link href="@Url.Content("/Content/admin/css/bootstrap.min.css")" rel="stylesheet" />
    <script src="/Scripts/jquery-1.10.2.min.js"></script>
    <script src="~/Content/MvcPager/MvcPager.js"></script>
</head>
<body>
    <div class="container-fluid">
        <ol class="breadcrumb">
            <li><a href="/set/admin/center">首页></a></li>
            <li><a href="#">代金券></a></li>
            <li class="active">商户代金券</li>
        </ol>
        <div class="portlet-body">
            <div class="navbar-form navbar-left" role="search">
                @if (actionString.Contains("Add"))
            {
            <a class="btn btn-primary btn-sm " data-toggle="modal" href="/coupon/BusinessCoupon/add"><span class="glyphicon glyphicon-plus" aria-hidden="true"></span>&nbsp;新增</a>
            }
                <button type="submit" class="btn btn-primary btn-sm " id="checkAll" onclick="CheckAll(this);">
                    <span class="glyphicon glyphicon-check" aria-hidden="true">全选</span>
                </button>
                @if (actionString.Contains("Delete"))
            {
            <button type="submit" class="btn btn-primary btn-sm" onclick="Delete(null, '/coupon/BusinessCoupon/delete', '/coupon/BusinessCoupon/list/@(Model.CurrentPageIndex - 1 > 1 ? Model.CurrentPageIndex - 1 : 1)');">
                <span class="glyphicon glyphicon-trash" aria-hidden="true"></span>&nbsp;删除
            </button>
            }
            </div>

            <form class="navbar-form navbar-left" id="formSearch" role="form" action="/coupon/businessCoupon/List">
                <div class="form-group">
                    @Html.DropDownList("Business", ViewData["Business"] as IEnumerable<SelectListItem>, "-所属商户-", new { id = "Category", @class = "form-control input-sm" })
                </div>
                <div class="form-group">
                    <select class="form-control input-sm" id="Status" name="Status">
                        <option value="">-选择状态-</option>
                        <option value="-1">待发布</option>
                        <option value="0">进行中</option>
                        <option value="1">已发完</option>
                        <option value="2">已过期</option>
                    </select>
                </div>
                <div class="form-group">
                    <input type="text" class="form-control input-sm" name="title" placeholder="请输入代金券标题" />
                </div>

                <button type="submit" class="btn btn-primary btn-sm ">
                    <span class="glyphicon glyphicon-zoom-in" aria-hidden="true"></span>&nbsp;搜索
                </button>
            </form>
            <div id="divTable">
                <table class="table table-bordered  table-condensed table-condensed  table-hover">
                    <thead>
                        <tr>
                            <th></th>
                            <th>所属商户</th>
                            <th>标题</th>
                            <th>封面图</th>
                            <th>面额</th>
                            <th>抵用</th>
                            <th>总量</th>
                            <th>已领取</th>
                            <th>状态</th>
                            <th>创建时间</th>
                            <th class="hidden-xs">操作</th>
                        </tr>
                    </thead>
                    <tbody>
                        @foreach (DataRow item in Model)
                    {
                    <tr>
                        <td>
                            <input type="checkbox" name="subBox" value="@item["Guid"]" id="ck@(item["Guid"])" />
                        </td>
                        <td>@item["BusinessName"]</td>
                        @if (item["Title"].ToString().Length >= 20)
                            {
                            <td id="@item["Guid"]" onmouseover="ShowMsg('@item["Guid"]','@item["Title"]')">@item["Title"].ToString().Substring(0, 20)  ...</td>
                            }
                            else
                            {
                            <td>@item["Title"]</td>
                            }
                        <td style="padding: 5px;">
                            <img onmouseover="MouseShowImage(this);" style="height:25px;width:40px;" alt="" src="@item["Image"]" onerror="this.src = '/Content/admin/img/coupon.jpg'" />
                        </td>
                        <td>@item["Value"]</td>
                        <td>消费满<b>@item["UseValueLimit"]</b> </td>
                        <td>@item["TotalCount"]</td>
                        <td>@item["MemberReceiveCount"]</td>
                        @switch (item["Status"].ToString())
                            {
                                case "-1":
                            <td><span class="label label-default">待发布</span></td>
                                    break;
                                case "0":
                            <td>进行中</td>
                                    break;
                                case "1":
                            <td>已领完</td>
                                    break;
                                case "2":
                            <td>已到期</td>
                                    break;
                                default:
                            <td>@item["Status"].ToString()</td>
                                    break;
                            }

                        <td>@Convert.ToDateTime(item["CreateTime"]).ToString("yyyy-MM-dd HH:MM:ss")</td>
                        <td>
                            @if (item["Status"].ToString() == "-1")
                                {
                                <buton class="btn btn-default btn-xs" onclick="Change('@item["Guid"]',0);">发布</buton>
                                }
                            @if (item["Status"].ToString() == "0")
                                {
                                <buton class="btn btn-default btn-xs" onclick="Change('@item["Guid"]',-1);">暂停</buton>
                                }
                            @if (actionString.Contains("Edit"))
                                {
                                <a class="btn btn-default btn-xs" title='编辑代金券' href="/coupon/businessCoupon/add/@item["Guid"]?pageIndex=@Model.CurrentPageIndex">编辑</a>
                                }
                            @if (actionString.Contains("Delete"))
                                {
                                <a class="btn btn-default btn-xs" title='' onclick="Delete('@item["Guid"]','/coupon/BusinessCoupon/delete','/coupon/BusinessCoupon/list/@(Model.CurrentPageIndex - 1 > 1 ? Model.CurrentPageIndex - 1 : 1)');">删除 </a>
                                }
                        </td>
                    </tr>
                    }
                    </tbody>
                </table>
                <div class="text-center">
                    <input type="hidden" value="@Model.TotalPageCount" id="TotalPageCount" />
                    <ul class="pagination">
                        <li>
                            <span aria-hidden="true">
                                @(Model.PageSize)条/页，@(Model.TotalPageCount)页, 共@(Model.TotalItemCount)条
                            </span>
                        </li>
                    </ul>
                    @Ajax.Pager(Model,
                    new PagerOptions
                    {
                        PageIndexParameterName = "pageIndex",
                        CssClass = "pagination",
                        FirstPageText = "首页",
                        LastPageText = "尾页",
                        PrevPageText = "上一页",
                        PageIndexBoxId = "pageIndexBox",
                        NextPageText = "下一页",
                        CurrentPagerItemTemplate = "<li class=\"active\"><a href=\"#\">{0}</a></li>",
                        DisabledPagerItemTemplate = "<li class=\"disabled\"><a>{0}</a></li>",
                        PagerItemTemplate = "<li>{0}</li>",
                        AutoHide = false,

                    }, new MvcAjaxOptions
                    {
                        UpdateTargetId = "divTable",
                        HttpMethod = "Post",
                        DataFormId = "formSearch",
                        EnableHistorySupport = false,
                        //OnSuccess = "EditMsg",
                        EnablePartialLoading = true
                    }
                    )
                    <ul class="pagination">
                        <li>
                            <span aria-hidden="true" style="padding: 2px 3px;">
                                跳转到第<input id="pageIndexBox" class="form-control input-sm" style="width:auto;display:inline-block;" oninput="InputPageIndex(this);" />
                                <button class="btn btn-primary btn-sm" id="goBtn1" onclick="GoPageIndex();">Go</button>
                            </span>
                        </li>
                    </ul>
                </div>
            </div>
        </div>
        @section Scripts{@{Html.RegisterMvcPagerScriptResource();}
        }
        <script src="/Content/layer/layer.js"></script>
        <script src="/Content/LwsJS/List.js"></script>
        <script type="text/javascript">
            function ShowMsg(id, msg) {
                layer.tips(msg, "#" + id, {
                    tips: [2, '#3595CC'],
                    time: 4000
                });
                $("#" + id).mouseout(function () {
                    layer.closeAll('tips'); //关闭所有的tips层
                });
            }
            function MouseShowImage(obj) {
                layer.open({
                    type: 1,
                    title: false,
                    closeBtn: 0,
                    shade: 0,
                    area: '516px',
                    content: "<img style='postion:fiexd;width:100%;' src='" + $(obj).attr("src") + "'/>"
                });
                $(obj).mouseout(function () {
                    layer.closeAll();
                });
            }
            function Change(guid, status) {
                $.post("/coupon/businessCoupon/SetStatus", { guid: guid, time: 2000, status: status }, function (data) {
                    if (data.succ) {
                        layer.msg(data.msg, { icon: 1 }, function () {
                            window.location.reload();
                        });


                    } else
                    { layer.msg(data.msg, { icon: 2 }); }
                });

            }
            function InputPageIndex(obj) {
                var pageIndex = $(obj).val().trim();
                if (parseInt(pageIndex) > parseInt($("#TotalPageCount").val())) {
                    $(obj).val($("#TotalPageCount").val());
                }
            }
            function GoPageIndex() {
                var pager = Webdiyer.MvcPagers[0];
                var pageIndex = $("#pageIndexBox").val().trim();
                var TotalPageCount = $("#TotalPageCount").val().trim();
                if (parseInt(pageIndex) > parseInt(TotalPageCount)) {
                    pageIndex = TotalPageCount;
                }
                if (pager != null) {
                    pager.goToPage(parseInt(pageIndex));
                } else
                { alert("找不到指定的MvcPager！"); }
            }
        </script>

        
        </div></body>
</html>
